/**
 * 时间 ： 2014-5-27 上午11:19:16
 * 作者 ： HaiTao
 * 描述 ： 当前类的描述信息
 **/
package com.laitaoo.controller
{
	import com.laitaoo.event.HomeEvent;
	import com.laitaoo.event.KindsEvent;
	import com.laitaoo.event.StockListEvent;
	import com.laitaoo.service.home.AddProductService;
	import com.laitaoo.service.home.AddYearService;
	import com.laitaoo.service.home.HomeService;
	import com.laitaoo.service.home.KindService;
	import com.laitaoo.service.home.StockListService;

	[Component]
	public class HomeController
	{
		public function HomeController()
		{
		}
		[Inject]
		public var homeService:HomeService;
		
		[Inject]
		public var addMouthService:AddYearService;
		
		[Inject]
		public var addProductService:AddProductService;
		
		[Inject]
		public var kindService:KindService;
		
		/**
		 * 进货信息业务逻辑处理类 
		 **/
		[Inject]
		public var stockListService:StockListService;
		
		[EventHandler]
		public function treeDataHandler():void{
			
			homeService.getTreeData();
		}
		
		/* 添加月份 */
		[EventHandler]
		public function addMouthHandler(event:HomeEvent):void{
			
			addMouthService.addYear(event.year);
		}
		/**
		 * 添加商品 
		 **/
		[EventHandler]
		public function addProductHandler(event:HomeEvent):void{
			
			addProductService.addProduct(event.productName,event.kindId);
		}
		[EventHandler]
		public function productListHandler(event:HomeEvent):void{
			
			addProductService.productList(event.dayId);
		}
		/** 
		 *保存编辑的数据
		 * */
		[EventHandler]
		public function saveProductByDayIdHandler(event:HomeEvent):void{
			addProductService.saveProduct(event.produtList,event.dayId);
		}
		
		[EventHandler]
		public function saveProductNameHandler(event:HomeEvent):void{
			
			addProductService.updateProductName(event.productName,event.productId);
		}
		[EventHandler]
		public function updateTotalInfoHandler(event:HomeEvent):void{
			
			addProductService.updateTotalInfoByDayId(event.totalCost,event.totalTunover,event.totalProfit,event.dayId);
		}
		[EventHandler]
		public function getTotalInfoByDayIdHandler(event:HomeEvent):void{
			addProductService.getTotalInfoByDayId(event.dayId);
		}
		
		[EventHandler]
		public function getMouthChartHandler(event:HomeEvent):void{
			addProductService.tempList = null;
			addProductService.getMouthChart(event.mouthXml);
		}
		
		/**
		 * 获取所有分类列表 
		 **/
		[EventHandler]
		public function getProductKindsHandler(event:HomeEvent):void{
			stockListService.getProductKinds();
		}
		
		[EventHandler]
		public function updateStockHandler(event:StockListEvent):void{
			stockListService.insertOrupdateStock(event.stockObj);
		}
		// ============================================================================================================
		
		/* 获取所有分类 */
		[EventHandler]
		public function allKindsHandler():void{
			kindService.getKinds();
		}
		// 添加分类
		[EventHandler]
		public function insertKindHandler(event:KindsEvent):void{
			kindService.insertKind(event.kindObj);
		}
		// 编辑分类
		[EventHandler]
		public function updateKindHandler(event:KindsEvent):void{
			kindService.updateKind(event.kindObj);
		}
		
		/**
		 * 获取指定商品的单价
		 * */
		[EventHandler]
		public function productPriceHandler(event:HomeEvent):void{
			
			homeService.getProductPrice(event.productId+"");
		}
	}
}


